{% extends '::backend.html.twig' %}
{% block contenido %}
{% block documentReadyJavascript %}
    {{ parent() }}
    <script type="text/javascript">
        $("#UserType_user_roles").select2({ width: 'resolve',formatSearching:function(){return "buscando..." },formatNoMatches:function(){return"no encontraos nada"}});
        $(".save").on('click', function(){
            return validateAjaxInputs();
        });
        
        function validateAjaxInputs() {
            $.validity.setup({
                //outputMode:"bootstrap"
                outputMode:"modal" 
            });

            $.validity.start();

            //validacion campo dni
            $("#UserType_dni")                        
            .require("El dni es obligatorio")                         
            .match("integer","Debe ser un nro.")
            .maxLength( 8, "El campo debe tener 8 digitos numericos" )
            .minLength( 8, "El campo debe tener 8 digitos numericos" ); 

            //validacion campo nombre
            $("#UserType_nombre")                        
            .require("Es obligatorio")
            .maxLength( 50, "El campo no puede superar los 50 caracteres")
            ;                         

            //validacion campo apellido
            $("#UserType_apellido")                        
            .require("Es obligatorio")
            .maxLength( 50, "El campo no puede superar los 50 caracteres");                         

            //validacion campo email
            $("#UserType_email")                        
            .require("Es obligatorio") 
            .match("email","Debe ser un mail valido.")
            .maxLength( 50, "El campo no puede superar los 50 caracteres");

            //validacion campo codigo postal
            $("#UserType_codigopostal")                        
            .match("integer","Debe ser un nro.")
            .maxLength( 4, "El campo debe tener 4 digitos numericos" )
            .minLength( 4, "El campo debe tener 4 digitos numericos" )
            ;

            //validacion campo direccion
            $("#UserType_direccion")                        
             .maxLength( 100, "El campo no puede superar los 100 caracteres")
            ;

            //validacion campo username
            $("#UserType_username")                        
            .require("Es obligatorio")
            .maxLength( 20, "El campo no puede superar los 20 caracteres")
            ;     

            var result = $.validity.end();

            // Return whether it's okay to proceed with the Ajax:
            return result.valid;
        }
    </script>
{% endblock documentReadyJavascript %}
<legend>Nuevo Usuario</legend>
<form class="form-horizontal" action="{{ path('user_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(form) }}>
    {{ form_widget(form._token) }} 
    {% include 'BackendBundle:Default:flashAlerts.html.twig'%}
    <fieldset> 
        <legend>Datos Personales</legend>
        <div class="control-group">
            <label class="control-label required" >Dni</label>
            <div class="controls">
                {{ form_errors(form.dni) }}
                {{ form_widget(form.dni) }}
            </div>
        </div>
        <div class="control-group">
            <label class="control-label required" >Nombre</label>
            <div class="controls">
                {{ form_errors(form.nombre) }}
                {{ form_widget(form.nombre) }}
            </div>
        </div>
        <div class="control-group">
            <label class="control-label required">Apellido</label>
            <div class="controls">
                {{ form_errors(form.apellido) }}
                {{ form_widget(form.apellido) }}
            </div>
        </div>
        <div class="control-group">
            <label class="control-label required">Email</label>
            <div class="controls">
                {{ form_errors(form.email) }}
                {{ form_widget(form.email) }}
                </div>
        </div>
        <div class="control-group">
            <label class="control-label required">Teléfono</label>
            <div class="controls">
                {{ form_errors(form.telefono) }}
                {{ form_widget(form.telefono) }}
            </div>
        </div>
        <div class="control-group">
            <label class="control-label required">Direcci&oacute;n</label>
            <div class="controls">
                {{ form_errors(form.direccion) }}
                {{ form_widget(form.direccion) }}
                </div>
        </div>
        <div class="control-group">
            <label class="control-label required">C&oacute;digo Postal</label>
                <div class="controls">
                    {{ form_errors(form.codigopostal) }}
                    {{ form_widget(form.codigopostal) }}
                </div>
        </div>
        <legend>Datos de Usuario</legend>
        <div class="control-group">
            <label class="control-label required" >Usuario</label>
            <div class="controls">
                {{ form_errors(form.username) }}
                {{ form_widget(form.username) }}
            </div>
        </div>
        <div class="control-group">
            <label class="control-label required" >Resetear Contraseña</label>
            <div class="controls">
                {{ form_errors(form.reset_password) }}
                {{ form_widget(form.reset_password) }}
            </div>
        </div>
           <div class="control-group">
            <label class="control-label required" >Rol</label>
            <div class="controls">
                {{ form_errors(form.user_roles) }}
                {{ form_widget(form.user_roles) }}
            </div>
        </div>
        <div class="control-group">
            <label class="control-label required" >Oficina</label>
            <div class="controls">
                {{ form_errors(form.oficina) }}
                {{ form_widget(form.oficina) }}
                <span class="help-inline">{{ form_errors(form.oficina) }}</span>
            </div>
        </div>
        <div class="form-actions">
            <button type="submit" class="btn btn-success save">
                <i class="icon-ok icon-black"></i> Guardar
            </button>
                <a id="btnCancelar" href="{{path('user')}}"class="btn btn-danger">
                <i class="icon-remove icon-black"></i> Cancelar
            </a>
        </div>
    </fieldset>
</form>

{% endblock %}

    